package com.eric.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.junit.Test;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eric.bean.User;
import com.eric.service.IUserService;

@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private IUserService userService;

    
    @RequestMapping("/showUser")
    public String toIndex(HttpServletRequest request, Model model) {
      // int userId = Integer.parseInt(request.getParameter("id"));
       int  userId1 = 1;
        User user = this.userService.getUserById(userId1);
        model.addAttribute("user", user);
        return "showUser";
    }
    
    @RequestMapping("/addUser")
    public void addUser(HttpServletRequest request, Model model){
    	User user = new User();
    	user.setId(101);
    	user.setAge(201);
    	user.setPassword("pwd");
    	user.setUserName("myname");
    	
    	int n = this.userService.adduser(user);
    	System.out.println(n);
    	
    }
}
